home *** CD-ROM | disk | FTP | other *** search
- #pragma once
- //
- // screendots is a prototypal class for the maintenance of collections of
- // dots on a macintosh screen. It simply stores pixel positions, and can be
- // used to do some simple things with this collection of positions.
- //
- // screendots is intended to be used either to display stereo dots or to display
- // monocularly visible dots. This could be split into two different classes, but
- // then we would also have to write two different versions of noisedots and flowdots.
- // In the current implementation one can switch seamlessly from using stereoscopic
- // dots to using monocular dots and vice versa, but that can not be done with
- // MoveDots. Instead EraseDots/EraseStereoDots must be called, followed by
- // SetStereoDots/SetDots. The maximum disparity allowed is given by
- // screenarea::max_error. No checks are made to ensure that this is the case.
- // NB: although the SetDots/EraseDots/MoveDots combo is relatively immune to wrong
- // ways of calling them (e.g. erasing is never done twice since 'current_intensity'
- // gets set to zero the first time) the stereo calls are less forgiving.
- //
- // 940822: added 'Set/Erase/MoveMultiDots' and make_a_multimove
- // to fulfill a request by Frans to move bars, squares, circles and crosses
- // over the screen. The array of ints passed to it is supposed to contain
- // offsets relative to the 'current position' of pixels to be 'hit' by the
- // operation requested. The offsets can encode both row and column offsets.
- // For instance, on a normal 13" (640x480 pixels screen) an offset of
- // 638 means: one row down, 2 pixels to the left from the 'real position'.
- // Users should use the utility function screenarea::compass2offsets to obtain
- // such an array.
- //
- // 941027: Finally discovered why the 'multi' calls crash horribly. It turns
- // out that this is because 'waste_area' is way too small when the figure
- // specified spans multiple display lines. => Heavily increased 'max_error'
- // (from 20 to 20.000) in order to hide this bug. Also made 'compass2offsets'
- // enter the Debugger when a too high offset is encountered.
- //
- class screendots : public screenarea
- {
- public:
- screendots( int numbits, int xpos, int ypos, int aantaldots);
- screendots( int numbits, screen_position where, int aantaldots);
-
- ~screendots();
- //
- // Call 'make_a_move()' to do a single step
- //
- void make_a_move( const unsigned char diff = 1);
- void make_a_multimove(
- const int *offsets, int numoffsets, const unsigned char diff = 1);
- void make_a_stereo_move( const char disparity = 10);
-
- void SetDots( const unsigned char diff = 1);
- void SetMultiDots(
- const int *offsets, int numoffsets, const unsigned char diff = 1);
- void SetStereoDots( const char disparity = 10);
-
- void EraseDots();
- void EraseMultiDots( const int *offsets, int numoffsets);
- void EraseStereoDots();
- //
- // MoveDots does Erase & Set in one loop to prevent flicker
- //
- void MoveDots( const unsigned char diff = 1);
- void MoveMultiDots(
- const int *offsets, int numoffsets, const unsigned char diff = 1);
- void MoveStereoDots( const char disparity = 10);
-
- protected:
- int numdots;
-
- unsigned char **dot_addresses;
- unsigned char **old_dot_addresses;
- //
- // compute_adresses should fill the array 'dot_addresses',
- // and not change 'old_dot_addresses'. 'swap' swaps the
- // contents of these two pointers.
- //
- virtual void compute_addresses() = 0;
- void swap();
-
- void init( int aantaldots);
-
- private:
- union
- {
- unsigned char current_intensity; // used by EraseDots
- char current_disparity; // used by EraseStereoDots
- };
- };
-
- inline screendots::screendots( int numbits, int xpos, int ypos, int aantaldots)
- : screenarea( numbits, xpos, ypos)
- {
- init( aantaldots);
- }
-
- inline screendots::screendots( int numbits, screen_position where, int aantaldots)
- : screenarea( numbits, where)
- {
- init( aantaldots);
- }
-
- inline screendots::~screendots()
- {
- delete dot_addresses;
- delete old_dot_addresses;
- }
-
- inline void screendots::swap()
- {
- unsigned char **temp = dot_addresses;
- dot_addresses = old_dot_addresses;
- old_dot_addresses = temp;
- }
-